﻿using System.Globalization;
using System.IO;
using System.Windows.Controls;
using System.Windows.Data;

namespace _03_View_Model_MVVM_Basics
{
	public class DriveConverter : IValueConverter
	{
		public static readonly DriveConverter Instance = new DriveConverter();

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var fullName = value as string;
			if (string.IsNullOrWhiteSpace(fullName)) return "";
			var name = fullName.Split("\\").LastOrDefault() ?? "";
			if (string.IsNullOrWhiteSpace(name)) return "磁盘";
			if (File.Exists(fullName)) return "文件";
			return "文件夹";
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
